/*
 * $Id: ColumnSimple.java 3373 2008-05-12 16:21:24Z xlv $
 * 
 * This code is part of the 'iText Tutorial'.
 * You can find the complete tutorial at the following address:

 * 
 * This code is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.
 * 
 * itext-questions@lists.sourceforge.net
 */
package com.mxpdf.examples.objects.columns;

import java.io.FileOutputStream;
import java.io.IOException;

import com.mxpdf.text.Document;
import com.mxpdf.text.DocumentException;
import com.mxpdf.text.Element;
import com.mxpdf.text.Font;
import com.mxpdf.text.Phrase;
import com.mxpdf.text.pdf.BaseFont;
import com.mxpdf.text.pdf.ColumnText;
import com.mxpdf.text.pdf.PdfContentByte;
import com.mxpdf.text.pdf.PdfWriter;

/**
 * Writes text in a column that can be added at an absolute position.
 */
public class ColumnSimple {
    
    /**
     * Demonstrating the use of ColumnText
     * @param args no arguments needed
     */
    public static void main(String[] args) {
        
        System.out.println("Simple Column");
        
        // step 1: creation of a document-object
        Document document = new Document();
        
        try {
            
            // step 2:
            // we create a writer that listens to the document
            // and directs a PDF-stream to a file
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("columnsimple.pdf"));
            
            // step 3: we open the document
            document.open();
            
            // step 4:
            
            // we grab the ContentByte and do some stuff with it
            PdfContentByte cb = writer.getDirectContent();
            
            BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font font = new Font(bf, 11, Font.NORMAL);
            
            ColumnText ct = new ColumnText(cb);
            ct.setSimpleColumn(60, 300, 100, 300 + 28 * 15, 15, Element.ALIGN_CENTER);
            ct.addText(new Phrase(15, "UNI\n", font));
            for (int i = 0; i < 27; i++) {
                ct.addText(new Phrase(15, uni[i] + "\n", font));
            }
            ct.go();
            cb.rectangle(103, 295, 52, 8 + 28 * 15);
            cb.stroke();
            ct.setSimpleColumn(105, 300, 150, 300 + 28 * 15, 15, Element.ALIGN_RIGHT);
            ct.addText(new Phrase(15, "char\n", font));
            for (int i = 0; i < 27; i++) {
                ct.addText(new Phrase(15, code[i] + "\n", font));
            }
            ct.go();
            ct.setSimpleColumn(160, 300, 500, 300 + 28 * 15, 15, Element.ALIGN_LEFT);
            ct.addText(new Phrase(15, "NAME" + "\n", font));
            for (int i = 0; i < 27; i++) {
                ct.addText(new Phrase(15, name[i] + "\n", font));
            }
            ct.go();
            
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
        
        // step 5: we close the document
        document.close();
    }

    /** a string array we want to output. */
    public static String[] uni = new String[27];
    /** a string array we want to output. */
    public static String[] code = new String[27];
    /** a string array we want to output. */
    public static String[] name = new String[27];
    
    static {
        uni[0]="\\u0152";
        code[0]="\u0152";
        name[0]="LATIN CAPITAL LIGATURE OE";
        
        uni[1]="\\u0153";
        code[1]="\u0153";
        name[1]="LATIN SMALL LIGATURE OE";
        
        uni[2]="\\u0160";
        code[2]="\u0160";
        name[2]="LATIN CAPITAL LETTER S WITH CARON";
        
        uni[3]="\\u0161";
        code[3]="\u0161";
        name[3]="LATIN SMALL LETTER S WITH CARON";
        
        uni[4]="\\u0178";
        code[4]="\u0178";
        name[4]="LATIN CAPITAL LETTER Y WITH DIAERESIS";
        
        uni[5]="\\u017D";
        code[5]="\u017D";
        name[5]="LATIN CAPITAL LETTER Z WITH CARON";
        
        uni[6]="\\u017E";
        code[6]="\u017E";
        name[6]="LATIN SMALL LETTER Z WITH CARON";
        
        uni[7]="\\u0192";
        code[7]="\u0192";
        name[7]="LATIN SMALL LETTER F WITH HOOK";
        
        uni[8]="\\u02C6";
        code[8]="\u02C6";
        name[8]="MODIFIER LETTER CIRCUMFLEX ACCENT";
        
        uni[9]="\\u02DC";
        code[9]="\u02DC";
        name[9]="SMALL TILDE";
        
        uni[10]="\\u2013";
        code[10]="\u2013";
        name[10]="EN DASH";
        
        uni[11]="\\u2014";
        code[11]="\u2014";
        name[11]="EM DASH";
        
        uni[12]="\\u2018";
        code[12]="\u2018";
        name[12]="LEFT SINGLE QUOTATION MARK";
        
        uni[13]="\\u2019";
        code[13]="\u2019";
        name[13]="RIGHT SINGLE QUOTATION MARK";
        
        uni[14]="\\u201A";
        code[14]="\u201A";
        name[14]="SINGLE LOW-9 QUOTATION MARK";
        
        uni[15]="\\u201C";
        code[15]="\u201C";
        name[15]="LEFT DOUBLE QUOTATION MARK";
        
        uni[16]="\\u201D";
        code[16]="\u201D";
        name[16]="RIGHT DOUBLE QUOTATION MARK";
        
        uni[17]="\\u201E";
        code[17]="\u201E";
        name[17]="DOUBLE LOW-9 QUOTATION MARK";
        
        uni[18]="\\u2020";
        code[18]="\u2020";
        name[18]="DAGGER";
        
        uni[19]="\\u2021";
        code[19]="\u2021";
        name[19]="DOUBLE DAGGER";
        
        uni[20]="\\u2022";
        code[20]="\u2022";
        name[20]="BULLET";
        
        uni[21]="\\u2026";
        code[21]="\u2026";
        name[21]="HORIZONTAL ELLIPSIS";
        
        uni[22]="\\u2030";
        code[22]="\u2030";
        name[22]="PER MILLE SIGN";
        
        uni[23]="\\u2039";
        code[23]="\u2039";
        name[23]="SINGLE LEFT-POINTING ANGLE QUOTATION MARK";
        
        uni[24]="\\u203A";
        code[24]="\u203A";
        name[24]="SINGLE RIGHT-POINTING ANGLE QUOTATION MARK";
        
        uni[25]="\\u20AC";
        code[25]="\u20AC";
        name[25]="EURO SIGN";
        
        uni[26]="\\u2122";
        code[26]="\u2122";
        name[26]="TRADE MARK SIGN";
    }
}